package com.yiwei.jmx.fragment;

import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.Spanned;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.allen.library.SuperButton;
import com.yiwei.jmx.R;
import com.yiwei.jmx.activity.ApplyStatusIngActivity;
import com.yiwei.jmx.activity.BankBindActivity;
import com.yiwei.jmx.activity.CarIdentityActivity;
import com.yiwei.jmx.activity.FaceIdentityActivity;
import com.yiwei.jmx.activity.HouseIdentityActivity;
import com.yiwei.jmx.activity.IdcardIdentityActivity;
import com.yiwei.jmx.activity.IdentityContactActivity;
import com.yiwei.jmx.activity.IncomeIdentityActivity;
import com.yiwei.jmx.activity.V3XueXinIdentityActivity;
import com.yiwei.jmx.activity.WorkIdentityActivity;
import com.yiwei.jmx.api.model.NotCertListModel;
import com.yiwei.jmx.constant.Const;
import com.yiwei.jmx.constant.UserInfoGlobal;
import com.yiwei.jmx.event.ChangeHomePageEvent;
import com.yiwei.jmx.util.PreferenceUtils;
import com.yiwei.jmx.util.Spans;
import com.yiwei.jmx.util.Util;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import kangcheng.com.lmzx_android_sdk_v10.bean.Fuction;
import kangcheng.com.lmzx_android_sdk_v10.commom.sdk.LmzxSdkImpl;

/**
 * Created by xsooy-pc on 18-8-31.
 */

public class IdentityTypeFragment extends BaseFragment {
    @BindView(R.id.img_icon)
    ImageView imgIcon;
    @BindView(R.id.txt_type)
    TextView txtType;
    @BindView(R.id.btn_submit)
    SuperButton btnSubmit;
    Unbinder unbinder;
    private NotCertListModel.DataBean totalData;


    private int[] apply_type = new int[]{R.mipmap.img_apply_car, R.mipmap.img_apply_fund, R.mipmap.img_apply_house, R.mipmap.img_apply_shebao, R.mipmap.img_apply_jd,
            R.mipmap.img_apply_income, R.mipmap.img_apply_work,  R.mipmap.img_apply_xuexin, R.mipmap.img_apply_zhima,R.mipmap.img_apply_success};

    @Override
    protected int setLayoutId() {
        return R.layout.fragment_identity_type_pager;
    }

    @Override
    protected void initView() {
        Bundle bundle = getArguments();
        totalData = bundle.getParcelable("data");
        if (totalData != null) {
            Spanned txt_info = Spans.with(this).font(totalData.name, getResources().getDimensionPixelSize(R.dimen.x28), 0xff000000).style(Typeface.BOLD).
                    font("\n最高提升" + totalData.rewards + "智信分", getResources().getDimensionPixelSize(R.dimen.x24), 0xff566F8E).
                    build();
            txtType.setText(txt_info);
            switch (totalData.remark) {
                case Const.IdentityType.car:
                    imgIcon.setImageResource(apply_type[0]);
                    break;
                case Const.IdentityType.housefund:
                    imgIcon.setImageResource(apply_type[1]);
                    break;
                case Const.IdentityType.house:
                    imgIcon.setImageResource(apply_type[2]);
                    break;
                case Const.IdentityType.socialsecurity:
                    imgIcon.setImageResource(apply_type[3]);
                    break;
                case Const.IdentityType.jd:
                    imgIcon.setImageResource(apply_type[4]);
                    break;
                case Const.IdentityType.income:
                    imgIcon.setImageResource(apply_type[5]);
                    break;
                case Const.IdentityType.work:
                    imgIcon.setImageResource(apply_type[6]);
                    break;
                case Const.IdentityType.xuexin:
                    imgIcon.setImageResource(apply_type[7]);
                    break;
                case Const.IdentityType.face_detect:
                    imgIcon.setImageResource(apply_type[8]);
                    break;
            }
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
    private void getLmSdkKeyOperator() {
        ((ApplyStatusIngActivity) getActivity()).getKey(UserInfoGlobal.getDealId(), true);
    }
    @OnClick(R.id.btn_submit)
    public void onViewClicked() {
        ((ApplyStatusIngActivity) getActivity()).bizType = totalData.remark;

        switch (totalData.remark) {
            case Const.IdentityType.yunyin:
                if (!((ApplyStatusIngActivity) getActivity()).initSuccess) {
                    getLmSdkKeyOperator();
                    return;
                }
                if (TextUtils.isEmpty(PreferenceUtils.getString(getContext(), "mobile", "")) || Const.IS_DEBUG) {
                    LmzxSdkImpl.getInstance().initOperatorPreNo(getContext(), "", true);
                } else {
                    LmzxSdkImpl.getInstance().initOperatorPreNo(getContext(), PreferenceUtils.getString(getContext(), "mobile", ""), false);
                }
                LmzxSdkImpl.getInstance().start(getContext(), Fuction.LMZXSDKFunctionMobileCarrie, 0 + "", Const.LIMU_CALLBACK);
                break;
            case Const.IdentityType.car:
                Util.startActivity(getContext(), CarIdentityActivity.class);
                break;

            case Const.IdentityType.face:
                if (!((ApplyStatusIngActivity) getActivity()).initSuccess) {
                    getLmSdkKeyOperator();
                    return;
                }
                LmzxSdkImpl.getInstance().setHTJCParas(getContext(), "true", "0129", "3", "8", "false", "true");
                LmzxSdkImpl.getInstance().start(getContext(), Fuction.LMZXSDKHTJC, 0 + "", Const.LIMU_CALLBACK);
                break;
            case Const.IdentityType.contacts:
                Util.startActivity(getContext(), IdentityContactActivity.class);
                break;

            case Const.IdentityType.email:
//                Util.startActivity(getContext(), V3EmailIdentityActivity.class);
                break;

            case Const.IdentityType.face_detect:
                Util.startActivity(getContext(), FaceIdentityActivity.class);
                break;

            case Const.IdentityType.house:
                Util.startActivity(getContext(), HouseIdentityActivity.class);
                break;

            case Const.IdentityType.housefund:
                if (!((ApplyStatusIngActivity) getActivity()).initSuccess) {
                    getLmSdkKeyOperator();
                    return;
                }
                LmzxSdkImpl.getInstance().start(getContext(), Fuction.LMZXSDKFunctionHousingFund, 0 + "", Const.LIMU_CALLBACK);
                break;

            case Const.IdentityType.income:
                Util.startActivity(getContext(), IncomeIdentityActivity.class);
                break;

            case Const.IdentityType.jd:
                if (!((ApplyStatusIngActivity) getActivity()).initSuccess) {
                    getLmSdkKeyOperator();
                    return;
                }
                LmzxSdkImpl.getInstance().start(getContext(), Fuction.LMZXSDKFunctionJD, 0 + "", Const.LIMU_CALLBACK);
                break;
            case Const.IdentityType.linkedin:
                if (!((ApplyStatusIngActivity) getActivity()).initSuccess) {
                    getLmSdkKeyOperator();
                    return;
                }
                LmzxSdkImpl.getInstance().start(getContext(), Fuction.LMZXSDKFunctionLinkedIn, 0 + "", Const.LIMU_CALLBACK);
                break;

            case Const.IdentityType.realname:
                Util.startActivity(getContext(), IdcardIdentityActivity.class);
                break;

            case Const.IdentityType.socialsecurity:
                if (!((ApplyStatusIngActivity) getActivity()).initSuccess) {
                    getLmSdkKeyOperator();
                    return;
                }
                LmzxSdkImpl.getInstance().start(getContext(), Fuction.LMZXSDKFunctionSocialSecurity, 0 + "", Const.LIMU_CALLBACK);
                break;

            case Const.IdentityType.taobao:
                if (!((ApplyStatusIngActivity) getActivity()).initSuccess) {
                    getLmSdkKeyOperator();
                    return;
                }
                LmzxSdkImpl.getInstance().start(getContext(), Fuction.LMZXSDKFunctionTaoBao, 0 + "", Const.LIMU_CALLBACK);
                break;
            case Const.IdentityType.work:
                Util.startActivity(getContext(), WorkIdentityActivity.class);
                break;
            case Const.IdentityType.xuexin:
                Util.startActivity(getContext(), V3XueXinIdentityActivity.class);
                break;
            case Const.IdentityType.bankcard:
                Util.startActivity(getContext(), BankBindActivity.class);
                break;

        }
    }

}
